package com.example.work_01;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;

public class GridActivity extends AppCompatActivity {
    GridLayout gridLayout;
    String[] chars= new String[]{
            "1","2","3",
            "4","5","6",
            "7","8","9",
            "0","+","-",
            "*","/","="
    };
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gridlayout);
        Button bn4=(Button) findViewById(R.id.bn4);
        gridLayout =(GridLayout) findViewById(R.id.root_grid);
        for(int i=0;i<chars.length;i++){
            Button bn=new Button(this);
            bn.setText(chars[i]);
            bn.setTextSize(40);
            bn.setPadding(15,15,15,15);
            GridLayout.Spec rowspec=GridLayout.spec(i/3);
            GridLayout.Spec columnspec=GridLayout.spec(i%3);
            GridLayout.LayoutParams params=new GridLayout.LayoutParams(rowspec,columnspec);
            params.setGravity(Gravity.FILL);
            gridLayout.addView(bn,params);
        }
        bn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(GridActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
  }
}
